package remato.domain.common.server;

import java.util.ArrayList;
import java.util.List;

import remato.domain.common.Category;
import remato.domain.common.CategoryRemote;
import remato.domain.common.Requirement;

public class CategoryRemoteImpl implements CategoryRemote {
	private Category category = null;
	
	public void setConcept(Category category) {
		this.category = category;
	}

	public int getNoRequirements() {
		return getNoRequirements(category);
	}

	private static Integer getNoRequirements(Category cat) {
		int noReqs = cat.getRequirements().size();
		for (Category subCat : cat.getCategoryChildren()) {
			noReqs += getNoRequirements(subCat);
		}
		return noReqs;
	}

	public List<Requirement> getAllRequirements() {
		return getAllRequirements(category);
	}
	
	private static List<Requirement> getAllRequirements(Category cat) {
		List<Requirement> result = new ArrayList<Requirement>(cat.getRequirements());
		for (Category subCat : cat.getCategoryChildren()) {
			result.addAll(getAllRequirements(subCat));
		}
		return result;
	}

}
